<template>
    <div class="box">
       <div class="head">新增图书</div>
       <div class="body">
        <form>
          <div class="mb-3">
            <label for="exampleInputEmail1" class="form-label">图书编号</label>
            <input type="email" disabled class="form-control" v-model="bookId"  aria-describedby="emailHelp">
          </div>
          <div class="mb-3">
            <label for="exampleInputPassword1" class="form-label">书名</label>
            <input type="email" v-model="bookName" class="form-control" >
          </div>
          <div class="mb-3">
            <label for="exampleInputPassword1" class="form-label">作者</label>
            <input type="email" v-model="author" class="form-control" >
          </div>
          <div class="mb-3">
            <label for="exampleInputPassword1" class="form-label">出版社</label>
            <input type="email" v-model="publish" class="form-control" >
          </div>
          <div class="mb-3">
            <label for="exampleInputPassword1" class="form-label">图书类别</label>
            <input type="email" v-model="category" class="form-control" >
          </div>
          <div class="mb-3">
            <label for="exampleInputPassword1" class="form-label">图书价格</label>
            <input type="email" v-model="price" class="form-control" >
          </div>
          <div class="mb-3">
            <label for="exampleInputPassword1" class="form-label">图书归还时间</label>
            <input type="email" v-model="deadline" class="form-control" id="exampleInputPassword1">
          </div>
        </form>
        <div class="body_buttons">
            <el-button type="info" size="medium">取消</el-button>
            <el-button type="primary" size="medium" @click="add_book">确认</el-button>
        </div>
       </div>
    </div>
</template>
<script>
export default{
  data(){
    return{
      bookId:"",
      bookName:"",
      publish:"",
      price:"",
      category:"",
      deadline:"",
      author:"",
    }
  },
  methods:{
    add_book(){
      // 
      this.axios.get('http://192.168.43.171:8081/books/insert', {
        params:{
          bookName:this.bookName,
          author:this.author,
          publish:this.publish,
          category:this.category,
          price:this.price,
          deadline:this.deadline,
          }
         }).then((response)=> {
                    // console.log(response.data);
                    if (response.data) {
                      console.log(response.data);
                      this.$message({
                       message: '添加成功',
                       type: 'success'
                      });
                    } else {
                      this.$message({
                     message: '注册失败',
                      type: 'warning'
                      });
                    }
                    // window.sessionStorage.setItem('token',response.data.phone)
                  }).catch(function (error) {
                    console.log(error);
                  });
    }
  },
  beforeRouteEnter:(to,from,next)=>{
   const ismaind=sessionStorage.getItem("ismaind")
   console.log(ismaind);
    if (ismaind==1) {
      next()
    } else {
      alert("无权限")
    }
  }
}
</script>
<style lang="less" scoped>
.box{
    width: 100%;
    height: 100%;
    // background-color: rgba(247, 248, 243,0.95);
    background-color: #fff;
    // background-color:pink;
    .head{
        position: absolute;
        top: 0px;
        font-size: 22px;
        text-align: center;
        line-height: 38px;
        width: 100%;
        height: 40px;
        // background-color: rgba(247, 248, 243,0.95);
        background-color: #fff;
    }
    .body{
        width: 80%;
        height: 86%;
        // background-color: #4dc1d6;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        padding-top: 40px;
        padding-right: 128px;
        padding-left: 128px;
        // background-color: rgba(247, 248, 243,0.95);
        background-color: #fff;
        .input_margin{
            margin-bottom: 32px;
        }
        .body_buttons{
            margin-left: 280px;
        }
    }
}

</style>